import { useUserStoreHook } from "@/store/modules/user";

/**
 * 获取当前用户的展商ID
 * @returns 展商ID，如果未登录则返回undefined
 */
export const getExhibitorId = (): number | undefined => {
  const userStore = useUserStoreHook();
  // 注意：exhibitor_id 可能为 0，这是有效值，不应该返回 undefined
  return userStore.exhibitor_id !== undefined && userStore.exhibitor_id !== null ? userStore.exhibitor_id : undefined;
};

/**
 * 获取当前用户的展商ID，如果未获取到则抛出错误
 * @returns 展商ID
 * @throws 如果未获取到展商ID则抛出错误
 */
export const getRequiredExhibitorId = (): number => {
  const exhibitor_id = getExhibitorId();
  if (!exhibitor_id) {
    throw new Error("未获取到展商ID，请重新登录");
  }
  return exhibitor_id;
};
